package com.hpjpw.ido.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hpjpw.ido.domain.Worker;
import com.hpjpw.ido.service.IWorkerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业人员Controller
 * 
 * @author hpj
 * @date 2021-01-02
 */
@Api(value ="WorkerController")
@RestController
@RequestMapping("/ido/worker")
public class WorkerController extends BaseController
{
    @Autowired
    private IWorkerService workerService;

    /**
     * 查询企业人员列表
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:list')")
    @GetMapping("/list")
    @ApiOperation("查询企业人员列表")
    public TableDataInfo list(Worker worker)
    {
        startPage();
        List<Worker> list = workerService.selectWorkerList(worker);
        return getDataTable(list);
    }

    /**
     * 导出企业人员列表
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:export')")
    @Log(title = "企业人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出企业人员列表")
    public AjaxResult export(Worker worker)
    {
        List<Worker> list = workerService.selectWorkerList(worker);
        ExcelUtil<Worker> util = new ExcelUtil<Worker>(Worker.class);
        return util.exportExcel(list, "worker");
    }

    /**
     * 获取企业人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取企业人员详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workerService.selectWorkerById(id));
    }

    /**
     * 新增企业人员
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:add')")
    @Log(title = "企业人员", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增企业人员")
    public AjaxResult add(@RequestBody Worker worker)
    {
        return toAjax(workerService.insertWorker(worker));
    }

    /**
     * 修改企业人员
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:edit')")
    @Log(title = "企业人员", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改企业人员")
    public AjaxResult edit(@RequestBody Worker worker)
    {
        return toAjax(workerService.updateWorker(worker));
    }

    /**
     * 删除企业人员
     */
    @PreAuthorize("@ss.hasPermi('ido:worker:remove')")
    @Log(title = "企业人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除企业人员")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workerService.deleteWorkerByIds(ids));
    }
}
